package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.ShoppingCart;
import com.itheima.reggie.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    //todo 显示购物车数据
    @GetMapping("/list")
    public R list(){
        R r = shoppingCartService.findByUserId();
        return r;
    }
    //todo 添加菜品购物车
    @PostMapping("/add")
    public R add(@RequestBody ShoppingCart shoppingCart){
        R r = shoppingCartService.add(shoppingCart);
        return r;
    }
    //todo 清空购物车
    @DeleteMapping("/clean")
    public R clean(){
        shoppingCartService.clean();
        return R.success("清空成功");
    }
    //todo 删除购物车单个商品
    @PostMapping("/sub")
    public R sub(@RequestBody ShoppingCart shoppingCart){
        R r = shoppingCartService.sub(shoppingCart);
        return r;
    }

}
